<?php if($type == 'host'){ ?>

<div id="sidebar">
<div id="">
    <h2><?php __('Actions'); ?></h2>
        <div class="actions">
            <ul>
                <li><?php echo $this->Html->link(__('Create New Event', true), array('action' => 'add')); ?></li>                
                <li><?php echo $this->Html->link(__('Upcoming Events', true), array('action' => 'index','events_host','upcoming')); ?> </li>
                <li><?php echo $this->Html->link(__('Past Events', true), array('action' => 'index','events_host', 'past')); ?> </li>
                <li><?php echo $this->Html->link(__('Edit my profile', true), array('controller' => 'hosts', 'action' => 'edit', $host_i)); ?>

                </ul>
        </div>
</div>
</div>
<?php }else{?>

<div id="sidebar">
<div id="">
    <h2><?php __('Actions'); ?></h2>
        <div class="actions">
            <ul>
                <li><?php echo $this->Html->link(__('Local events', true), array('controller' => 'events', 'action' => 'index','local_events')); ?> </li>

                <li><?php echo $this->Html->link(__('My RSVPs', true), array('controller' => 'events', 'action' => 'index','rsvps')); ?> </li>

                <li><?php echo $this->Html->link(__('My invites', true), array('controller' => 'events', 'action' => 'index','invites')); ?> </li>

                <li><?php echo $this->Html->link(__('Edit my profile', true), array('controller' => 'users', 'action' => 'edit_profile',$id_user)); ?></li>
            </ul>
        </div>
</div>
</div>

<?php } ?>

<div class="events index">
        
    <?php if($type == 'host'){ ?>
    <h2><?php __('Events'); ?></h2>
    <?php }else{ ?>
    <?php if ($ev_type == 'local_events'){?>
    <h2><?php __('Local events'); ?></h2>
    <?php }elseif ($ev_type == 'rsvps') { ?>
    <h2><?php __('Your RSVP events'); ?></h2>
    <?php }else{ ?>
    <h2><?php __('Invites'); ?></h2>
    <?php }?>
    
    <table>
        <tr>
            <td class="actions" colspan="6">    
            <?php echo $this->Html->link(__('Upcoming', true), array('controller' => 'events', 'action' => 'index',$ev_type,'upcoming')); ?>
            <?php echo $this->Html->link(__('Past', true), array('controller' => 'events', 'action' => 'index',$ev_type,'past')); ?>

            </td>
        </tr>
    </table>
            
    <?php } ?>

    <?php 
    
        if(!empty($events)){
    
            $i = 0;
            foreach ($events as $event):
                $class = null;
                if ($i++ % 2 == 0) {
                    $class = ' class="altrow"';
                }
    ?>
    
    <h3><?php echo $event['Event']['event_name'];?></h3>
    
    <div class="event_listing">
        <div class="event_listing_left">
            <?php
                if(file_exists('img/event/'.$event['Event']['id'].'.jpg')){
                    echo $this->Html->image('event/'.$event['Event']['id'].'.jpg',array('height'=>'90','width'=>'90'));
                }else{
                    echo $this->Html->image('default_event.jpg',array('height'=>'90','width'=>'90'));
                }
            ?>
        </div>
        <div class="event_listing_right">
            <p><span class="small_title">Location: </span><?php echo $event['Event']['venue_addr1'].', '. $event['Event']['venue_city'].', '. $event['Event']['venue_state'].' '. $event['Event']['venue_postal']; ?></p>
            <p><span class="small_title">Start Time: </span><?php echo $event['Event']['event_start']; ?></p>
            <p><span class="small_title">End Time: </span><?php echo $event['Event']['event_end']; ?></p>
            <p><span class="small_title">Details: </span><?php echo $event['Event']['description']; ?></p>
            <?php 
            if($type == 'host'){
                echo "<p><span class=\"small_title\">Host type: </span>";
                    echo $event['EventHost']['host_type'];
                    echo "</p>";
                    }?>
          
        </div>
        <div id="event_listing_clear">
            <table>
                <tr>
                    
                    <td class="actions" colspan="6">  
                    <?php if($type == 'host'){?>
                    <?php if($event['EventHost']['host_type'] == 'p'){?>
                    <?php if($event_time == 'upcoming'){ ?>
                    <?php echo $this->Html->link(__('View & Co-host', true), array('action' => 'view','events_host',$event['Event']['id'])); ?>
                  
                    <?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $event['Event']['id'])); ?>
                    <?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $event['Event']['id']), null, sprintf(__('Are you sure you want to delete  %s?', true), $event['Event']['event_name'])); ?>
                    <?php 
                    if($event['Event']['event_type'] == 'invite'){
                        echo $this->Html->link(__('Invite', true), array('controller' => 'invites', 'action' => 'index', $event['Event']['id']));
                    }
                    ?>
                    <?php echo $this->Html->link(__('Report', true), array('controller' => 'events', 'action' => 'report',$event['Event']['id'])); ?>
                    <?php }?>
                    

                    <?php if($event_time == 'past'){ ?>                    
                    <?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $event['Event']['id']), null, sprintf(__('Are you sure you want to delete  %s?', true), $event['Event']['event_name'])); ?>                    
                    <?php echo $this->Html->link(__('Report', true), array('controller' => 'events', 'action' => 'report',$event['Event']['id'], 'past')); ?>
                    <?php }?>
                    <?php }?>

                    <?php if($event['EventHost']['host_type'] == 's'){?>
                    <?php if($event_time == 'upcoming'){ ?>
                    <?php echo $this->Html->link(__('View & Co-host', true), array('action' => 'view','events_host',$event['Event']['id'])); ?>                   
                    <?php echo $this->Html->link(__('Invite', true), array('controller' => 'invites', 'action' => 'index', $event['Event']['id'])); ?>
                    <?php echo $this->Html->link(__('Report', true), array('controller' => 'events', 'action' => 'report',$event['Event']['id'])); ?>
                    <?php }?>


                    <?php if($event_time == 'past'){ ?>                    
                    <?php echo $this->Html->link(__('Report', true), array('controller' => 'events', 'action' => 'report',$event['Event']['id'])); ?>
                    <?php }?>
                    <?php }?>
                    <?php }?>

                    <?php if($type == 'user'){ ?>
                    <?php if(isset($ev_type) && ($ev_type != '')){ ?>
                    <?php echo $this->Html->link(__('View details', true), array('action' => 'view', $ev_type, $event['Event']['id'])); ?>
                    <?php }else{ ?>
                    <?php echo $this->Html->link(__('View details', true), array('action' => 'view', 'Local_events', $event['Event']['id'])); ?>
                    <?php }?>
                    <?php }?>


                    </td>
                </tr>            
            </table>
        </div>
        <div id="event_listing_clear"></div>
    </div>
    <p>
        <?php
            endforeach;

            echo $this->Paginator->counter(array(
                            'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
                        ));
        ?>
    </p>

    <div class="paging">
        <?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class' => 'disabled')); ?>
                	 | 	<?php echo $this->Paginator->numbers(); ?>
                        |
        <?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));

        }else{
            if($event_time == 'upcoming'){
                echo '<h3>You have no upcoming events in this section</h3>';
            } else {
                echo '<h3>You have no past events in this section</h3>';
            }
        }
        ?>
    </div>
</div>

